import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    public int[] nextGreaterElements(int[] nums) {
        int n = nums.length;
        int[] ret = new int[n];
        //ret的初始化
        for(int i = 0; i < n; i++) ret[i] = -1;
        Stack<Integer> stack = new Stack<>();
        stack.push(0);
        for(int i = 1; i < n * 2; i++){
            int j = i % n;//模拟循环的过程
            if(nums[j] <= nums[stack.peek()]){
                stack.push(j);
                continue;
            }
            while(!stack.isEmpty() && nums[j] > nums[stack.peek()] ){
                ret[stack.peek()] = nums[j];
                stack.pop();
            }
            stack.push(j);
        }
        return ret;
    }
}